package org.come.Jpanel;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.JTextField;

import org.come.Frame.ZhuFrame;
import org.come.socket.Agreement;
import org.come.socket.SendMessageUntil;

import com.tool.btn.FormsOnOffBtn;
import com.tool.btn.RoleCaoZuoBtn;
import com.tool.tcpimg.UIUtils;
import com.updateNew.MyIsif;

//TODO 查询面板
/**
 *
 * @author gl
 *
 */
public class FindDropJpanel extends JPanel {

    private static final long serialVersionUID = 1L;
    // 一个输入框
    private static JTextField findName;
    private RoleCaoZuoBtn sureGive, deleteGive;// 确定查询，取消

    public FindDropJpanel() throws Exception {

        // 键盘监听
        this.setPreferredSize(new Dimension(350, 269));
        this.setBackground(UIUtils.Color_BACK);
        this.setLayout(null);



        String style = MyIsif.getStyle();
        if ("水墨UI".equals(style)) {
            findName = new JTextField();// 查询的物品名称输入
            findName.setBounds(70, 119, 205, 20);
            findName.setOpaque(false);
            findName.setBorder(BorderFactory.createEmptyBorder());
            findName.setForeground(Color.white);
            findName.setCaretColor(Color.white);
            findName.setFont(new Font("宋体",Font.PLAIN,15));
            this.add(findName);
            sureGive = new RoleCaoZuoBtn("inkImg/newbutton/B21.png", 1, "搜 索", 600, UIUtils.COLOR_BLACK);
            sureGive.setBounds(70, 190, 79, 24);
            this.add(sureGive);
            deleteGive = new RoleCaoZuoBtn("inkImg/newbutton/B21.png", 1, "取 消", 601, UIUtils.COLOR_BLACK);
            deleteGive.setBounds(202, 190, 79, 24);
            this.add(deleteGive);
        } else {
            findName = new JTextField();// 查询的物品名称输入
            findName.setBounds(128, 68, 128, 20);
            findName.setOpaque(false);
            findName.setBorder(BorderFactory.createEmptyBorder());
            findName.setForeground(Color.white);
            findName.setCaretColor(Color.white);
            findName.setFont(new Font("宋体",Font.PLAIN,15));
            this.add(findName);
            sureGive = new RoleCaoZuoBtn("inkImg/hongmu/50x50.png", 1, "搜索", 600, UIUtils.COLOR_BTNPUTONG2);
            sureGive.setBounds(82, 100, 68, 26);
            this.add(sureGive);
            deleteGive = new RoleCaoZuoBtn("inkImg/hongmu/50x50.png", 1, "取消", 601, UIUtils.COLOR_BTNPUTONG2);
            deleteGive.setBounds(182, 100, 68, 26);
            this.add(deleteGive);
        }
    }


    /** 查询确定 */
    public static void findEnsure() {
        if(findName == null || findName.getText() == null || findName.getText().length() == 0) {
            ZhuFrame.getZhuJpanel().addPrompt2("你要查什么呢？");
            return;
        }

        String senmes=Agreement.getAgreement().findDropAgreement(findName.getText());
        SendMessageUntil.toServer(senmes);//向服务器发送信息
    }

    private ImageIcon icon;
    private ImageIcon icon1;

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        String style = MyIsif.getStyle();
        if ("水墨UI".equals(style)) {
            if (icon == null)
                icon = new ImageIcon("inkImg/newbackground/B330.png");
            g.drawImage(icon.getImage(), 0, 0, 350, 269, this);
        } else{
            if (icon1 == null)
                icon1 = new ImageIcon("img/xy2uiimg/chaxun.png");
            g.drawImage(icon1.getImage(), 0, 0, 296, 257, this);
        }
    }

    public RoleCaoZuoBtn getSureGive() {
        return sureGive;
    }

    public void setSureGive(RoleCaoZuoBtn sureGive) {
        this.sureGive = sureGive;
    }

    public RoleCaoZuoBtn getDeleteGive() {
        return deleteGive;
    }

    public void setDeleteGive(RoleCaoZuoBtn deleteGive) {
        this.deleteGive = deleteGive;
    }

    public static JTextField getFindName() {
        return findName;
    }

    public static void setFindName(JTextField findName) {
        FindDropJpanel.findName = findName;
    }

}
